package code;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import comm.IbatisLoader;

import com.ibatis.sqlmap.client.SqlMapClient;

public class codeDao {
	private IbatisLoader 	iBatis;
	private SqlMapClient 	sqlMapper;
	
	public codeDao(){
		this.sqlMapper = iBatis.setConfig();
	}
	/**
	 * 由ъ뒪�듃
	 * @return
	 */
	public List getList(String searchGubn, String searchValue, int selectPage, int pageSize){
		List returnValue	= new ArrayList();
		if (selectPage == 0)	selectPage = 1;
		if (pageSize == 0)		pageSize = 10;
		int startPos	= ((selectPage-1)*pageSize);
		Map<String, Object> param = new HashMap<String, Object>();
		
		param.put("searchGubn", searchGubn);
		param.put("searchValue", searchValue);
		param.put("startPos", startPos);
		param.put("pageSize", pageSize);
		
		try{
			returnValue = (List)sqlMapper.queryForList("code.hdrcode_select",param);
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}
	/**
	 * 寃뚯떆臾� �쟾泥� 媛��닔
	 * @return
	 */
	public int getCount( String searchGubn, String searchValue){
		int returnValue = 0;
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("searchGubn", searchGubn);
		param.put("searchValue", searchValue);
		try{
			returnValue = ((Integer)sqlMapper.queryForObject("code.hdrcode_count",param)).intValue();	
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}
	/**
	 * 由ъ뒪�듃
	 * @return
	 */
	public List getDtlList(String hdrcode){
		List returnValue	= new ArrayList();
		Map<String, Object> param = new HashMap<String, Object>();
		
		param.put("hdrcode", hdrcode);
		
		try{
			returnValue = (List)sqlMapper.queryForList("code.dtlcode_select",param);
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}
	
	/**
	 * �뵒�뀒�씪 �듅�젙 肄붾뱶紐낆쓣 媛�吏�怨� �삩�떎
	 * @return
	 */
	public String getDtlName(String hdrcode,String dtlcode){
		String returnValue	= "" ;
		Map<String, Object> param = new HashMap<String, Object>();
		
		param.put("hdrcode", hdrcode);
		param.put("code", dtlcode);
		
		try{
			returnValue = (String)sqlMapper.queryForObject("code.dtlcode_selectname",param);
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}
	/**
	 * 寃뚯떆臾� �쟾泥� 媛��닔
	 * @return
	 */
	public int getDtlCount(String hdrcode){
		int returnValue = 0;
		Map<String, Object> param = new HashMap<String, Object>();
		param.put("hdrcode", hdrcode);
		try{
			returnValue = ((Integer)sqlMapper.queryForObject("code.dtlcode_count",param)).intValue();	
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}	
	
	/**
	 * �닔�젙
	 * @param boardmodel
	 * @return
	 */
	public boolean getUpdate(codeModel codemodel){
		boolean returnValue = false;
		try{
			if(sqlMapper.update("code.update", codemodel) > 0){
				returnValue = true;
			}else{
				returnValue = false;
			}
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}
	
	/**
	 * �벑濡�
	 * @param boardmodel
	 * @return
	 */
	public boolean getInsert(codeModel codemodel){
		boolean returnValue = true;
		try{
			sqlMapper.update("code.insert", codemodel);
		}catch (Exception e) {
			// TODO: handle exception
			returnValue = false;
		}
		return returnValue;
	}
	/**
	 * �궘�젣
	 * @param data_id
	 * @return
	 */
	public boolean getDelete(codeModel codemodel){
		boolean returnValue = true;
		try{
			sqlMapper.delete("code.delete", codemodel);
		}catch (Exception e) {
			// TODO: handle exception
			returnValue = false;
		}
		return returnValue;
	}
	
	/**
	 * �닔�젙
	 * @param boardmodel
	 * @return
	 */
	public boolean getDtlUpdate(codeModel codemodel){
		boolean returnValue = false;
		try{
			if(sqlMapper.update("code.dtlupdate", codemodel) > 0){
				returnValue = true;
			}else{
				returnValue = false;
			}
		}catch (Exception e) {
			// TODO: handle exception
		}
		return returnValue;
	}
	
	/**
	 * �벑濡�
	 * @param boardmodel
	 * @return
	 */
	public boolean getDtlInsert(codeModel codemodel){
		boolean returnValue = true;
		try{
			sqlMapper.update("code.dtlinsert", codemodel);
		}catch (Exception e) {
			// TODO: handle exception
			returnValue = false;
		}
		return returnValue;
	}
	/**
	 * �궘�젣
	 * @param data_id
	 * @return
	 */
	public boolean getDtlDelete(codeModel codemodel){
		boolean returnValue = true;
		try{
			sqlMapper.delete("code.dtldelete", codemodel);
		}catch (Exception e) {
			// TODO: handle exception
			returnValue = false;
		}
		return returnValue;
	}
}
